/*
package org.example.lost.service.impl;


import org.example.lost.entity.Role;
import org.example.lost.entity.UserInfo;
import org.example.lost.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

*/
/**
 * @Author hxy
 * @Date 2021/3/11 23:41
 * @Version 1.0
 *//*

@Service
@Primary
public class UserDetailServiceImpl implements UserDetailsService {
    @Autowired
    private UserMapper userMapper;

    */
/**
     * 需新建配置类注册一个指定的加密方式Bean，或在下一步Security配置类中注册指定
     *//*

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserInfo user = userMapper.selectByPhone(username);
        if(user == null){
            throw new UsernameNotFoundException("用户不存在");
        }
        //获取用户角色
        Role role = userMapper.selectByUserId(user.getUserId());
        if(role == null){
            throw new UsernameNotFoundException("角色不存在");
        }

        //角色集合
        List<GrantedAuthority> authorities=new ArrayList<>();

        //角色必须以“ROLE_"开头
        authorities.add(new SimpleGrantedAuthority(role.getRoleName()));

        System.out.println(user.getUserPwd());
        return new User(user.getUserPhone(),
                user.getUserPwd(),
                authorities);
    }
}
*/
